package com.attendance.www.hr.service.impl;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.annotation.Resource;

import org.apache.commons.lang.time.DateUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFColor;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import com.attendance.www.hr.beans.AttendanceBean;
import com.attendance.www.hr.beans.ReportAttendanceBean;
import com.attendance.www.hr.beans.ReportAttendanceParam;
import com.attendance.www.hr.beans.RestVacationBean;
import com.attendance.www.hr.beans.RetroactiveBean;
import com.attendance.www.hr.beans.TaskBean;
import com.attendance.www.hr.constant.AppConstant;
import com.attendance.www.hr.dao.mapper.AttendanceExtMapper;
import com.attendance.www.hr.dao.mapper.AttendanceReportExtMapper;
import com.attendance.www.hr.dao.mapper.AttendanceReportMapper;
import com.attendance.www.hr.dao.mapper.EmployeeExtMapper;
import com.attendance.www.hr.dao.mapper.EmployeeMapper;
import com.attendance.www.hr.dao.mapper.EmployeeRoleExtMapper;
import com.attendance.www.hr.dao.mapper.EmployeeRoleMapper;
import com.attendance.www.hr.dao.mapper.FurloughBalanceMapper;
import com.attendance.www.hr.dao.mapper.ReportAttendanceExtMapper;
import com.attendance.www.hr.dao.mapper.RequestMapper;
import com.attendance.www.hr.dao.mapper.RetroactiveExtMapper;
import com.attendance.www.hr.dao.mapper.SystemConfigureMapper;
import com.attendance.www.hr.dao.mapper.TaskExtMapper;
import com.attendance.www.hr.dao.mapper.TaskMapper;
import com.attendance.www.hr.entitys.AttendanceReport;
import com.attendance.www.hr.entitys.AttendanceReportExample;
import com.attendance.www.hr.entitys.Employee;
import com.attendance.www.hr.entitys.EmployeeExample;
import com.attendance.www.hr.entitys.EmployeeRole;
import com.attendance.www.hr.entitys.EmployeeRoleExample;
import com.attendance.www.hr.entitys.FurloughBalance;
import com.attendance.www.hr.entitys.FurloughBalanceExample;
import com.attendance.www.hr.entitys.Request;
import com.attendance.www.hr.entitys.RequestExample;
import com.attendance.www.hr.entitys.SystemConfigure;
import com.attendance.www.hr.entitys.SystemConfigureExample;
import com.attendance.www.hr.exception.ResultFaultException;
import com.attendance.www.hr.service.IAttendanceReportService;
import com.attendance.www.hr.service.IReportResultService;
import com.attendance.www.hr.service.IReportService;
import com.attendance.www.hr.utils.FactorialUtils;

@Service
public class AttendanceReportServiceImpl implements IAttendanceReportService {
	@Resource
	private AttendanceExtMapper attendanceExtDao;
	@Resource
	private AttendanceReportExtMapper attendanceReportExtDao;
	@Resource
	private AttendanceReportMapper attendanceReportDao;
	@Resource
	private RetroactiveExtMapper retroactiveExtDao;
	@Resource
	private EmployeeMapper employeeDao;
	@Resource
	private EmployeeExtMapper employeeExtDao;
	@Resource
	private FurloughBalanceMapper furloughBalanceDao;
	@Resource
	private SystemConfigureMapper systemConfigureDao;
	@Resource
	private RequestMapper requestDao;
	@Resource
	private IReportResultService reportResultService;
	@Resource
	private TaskExtMapper taskExtDao;
	@Resource
	private TaskMapper taskDao;
	@Resource
	private EmployeeRoleMapper employeeRoleDao;
	@Resource
	private EmployeeRoleExtMapper employeeRoleExtDao;
	@Resource
	private ReportAttendanceExtMapper reportExtDao;
	@Resource
	private IReportService reportService;
	
	/**
	 * 每日生成考勤报表数据
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	@Override
	public void saveAttendanceReport(Date startDate,Date endDate, Integer empEmployeeId) {
		//取年份
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(startDate);
		int thatYear = calendar.get(Calendar.YEAR);
		int lastYear = thatYear - 1;
		
		//年假查询参数
		RestVacationBean restVacationBean=new RestVacationBean();
		restVacationBean.setFurloughType(1);
		restVacationBean.setStartDate(startDate);
		
		EmployeeExample employeeExample=new EmployeeExample();
		List<Employee> employeeList=employeeDao.selectByExample(employeeExample);
		Map<Integer, Employee> employeeMap = new HashMap<Integer, Employee>();
		//生成出员工id列表
		List<Integer> employeeIds = new ArrayList<Integer>();
		for(int ei=0;ei<employeeList.size();ei++){
			employeeIds.add(employeeList.get(ei).getEmployeeId());
			employeeMap.put(employeeList.get(ei).getEmployeeId(), employeeList.get(ei));
		}

		//年假
		FurloughBalanceExample furloughBalanceExample=new FurloughBalanceExample();
		furloughBalanceExample.createCriteria()
		.andEmployeeIdIn(employeeIds)
		.andFurloughBalanceTypeEqualTo(1)
		.andYearEqualTo(Integer.toString(thatYear));
		List<FurloughBalance> fList=furloughBalanceDao.selectByExample(furloughBalanceExample);
		
		//去年
		FurloughBalanceExample furloughBalanceExample2=new FurloughBalanceExample();
		furloughBalanceExample2.createCriteria()
		.andEmployeeIdIn(employeeIds)
		.andFurloughBalanceTypeEqualTo(1)
		.andYearEqualTo(Integer.toString(lastYear));
		List<FurloughBalance> lastFList=furloughBalanceDao.selectByExample(furloughBalanceExample2);
		
		//查询当天年假申请
		RequestExample requestExample=new RequestExample();
		requestExample.createCriteria()
		.andEmployeeIdIn(employeeIds)
		.andRequestTypeEqualTo(1)
		.andReportYearEqualTo(thatYear)
		.andApprovalStateEqualTo(1);
		List<Request> rList=requestDao.selectByExample(requestExample);

		Map<Integer, List<Request>> thatYearRequestMap = new HashMap<Integer, List<Request>>();
		for(int ri=0;ri<rList.size();ri++){
			if (thatYearRequestMap.containsKey(rList.get(ri).getEmployeeId())) {
				List<Request> eList = thatYearRequestMap.get(rList.get(ri).getEmployeeId());
				eList.add(rList.get(ri));
				thatYearRequestMap.put(rList.get(ri).getEmployeeId(), eList);
			} else {
				List<Request> eList = new ArrayList<Request>();
				eList.add(rList.get(ri));
				thatYearRequestMap.put(rList.get(ri).getEmployeeId(), eList);
			}
		}
		
		//在申请中的去年年假时长
		RequestExample requestExample2=new RequestExample();
		requestExample2.createCriteria()
		.andEmployeeIdIn(employeeIds)
		.andRequestTypeEqualTo(1)
		.andReportYearEqualTo(lastYear)
		.andApprovalStateEqualTo(1);
		List<Request> rLastList=requestDao.selectByExample(requestExample2);

		Map<Integer, List<Request>> lastYearRequestMap = new HashMap<Integer, List<Request>>();
		for(int lyi=0;lyi<rLastList.size();lyi++){
			if (lastYearRequestMap.containsKey(rLastList.get(lyi).getEmployeeId())) {
				List<Request> eList = lastYearRequestMap.get(rLastList.get(lyi).getEmployeeId());
				eList.add(rLastList.get(lyi));
				lastYearRequestMap.put(rLastList.get(lyi).getEmployeeId(), eList);
			} else {
				List<Request> eList = new ArrayList<Request>();
				eList.add(rLastList.get(lyi));
				lastYearRequestMap.put(rLastList.get(lyi).getEmployeeId(), eList);
			}
		}
		
		//调用存储过程
		attendanceReportExtDao.generateAttendanceReport(startDate, endDate, empEmployeeId);
		
		//查询系统配置表
		List<SystemConfigure> systemConfigureList=systemConfigureDao.selectByExample(new SystemConfigureExample());
		
		//更改计算值
		AttendanceReportExample attendanceReportExample=new AttendanceReportExample();
		if (empEmployeeId==null) {
			attendanceReportExample.createCriteria()
			.andAttendanceReportDateEqualTo(endDate);
		} else {
			attendanceReportExample.createCriteria()
			.andAttendanceReportDateEqualTo(endDate)
			.andEmployeeIdEqualTo(empEmployeeId);
		}
		List<AttendanceReport> attendanceReportList=attendanceReportDao.selectByExample(attendanceReportExample);
		
		//把统计信息放入报表对象中
		for (int i=0;i<attendanceReportList.size();i++) {
			AttendanceReport attendanceReport = attendanceReportList.get(i);
			Integer employeeId=attendanceReport.getEmployeeId();
			
			AttendanceReport attendanceReportYear = new AttendanceReport();
			
			//员工应出勤天数(应出勤天数=当月排班+法定假-产假（按排班休的产假）)
			/*if (attendanceReport.getRestBornUsed()!= null) {
				attendanceReport.setRealAttendanceDays(attendanceReport.getRealAttendanceDays()-attendanceReport.getRestBornUsed());
			} else {
				attendanceReport.setRealAttendanceDays(attendanceReport.getRealAttendanceDays());
			}*/
			
			//年假
			RestVacationBean newRestVacationBean = reportResultService.getLastYearYearFurlough(restVacationBean, employeeId,systemConfigureList,employeeMap,fList,lastFList,thatYearRequestMap,lastYearRequestMap);
			//可享受年假
//							reportInfoList.get(i).setYearRestYearAll(newRestVacationBean.getTotalVacation().divide(new BigDecimal(60*8), 2, BigDecimal.ROUND_HALF_UP).floatValue());
			attendanceReport.setYearRestYearAll(newRestVacationBean.getTotalVacation().floatValue());
			//员工请年假天数
			attendanceReport.setYearRestYearUsed((newRestVacationBean.getTotalVacation().subtract(newRestVacationBean.getRealRestVacation())).floatValue());
			//剩余年假
			attendanceReport.setRestYearRemain(newRestVacationBean.getRealRestVacation().floatValue());
			//去年可享受年假天数
			attendanceReport.setYearRestLastYearAll(newRestVacationBean.getLastYearTotalVacation().floatValue());
			//员工请去年年假天数
			attendanceReport.setYearRestLastYearUsed((newRestVacationBean.getLastYearTotalVacation().subtract(newRestVacationBean.getRealLastYearRestVacation())).floatValue());
			
//			attendanceReportDao.updateByPrimaryKeySelective(attendanceReport);
			
			attendanceReportYear.setYearAbsentCount(attendanceReport.getYearAbsentCount());
			attendanceReportYear.setYearLateCount(attendanceReport.getYearLateCount());
			attendanceReportYear.setYearLeaveEarlyCount(attendanceReport.getYearLeaveEarlyCount());
			attendanceReportYear.setYearOvertimeHoliday(attendanceReport.getYearOvertimeHoliday());
			attendanceReportYear.setYearOvertimeNomal(attendanceReport.getYearOvertimeNomal());
			attendanceReportYear.setYearOvertimeWeekend(attendanceReport.getYearOvertimeWeekend());
			attendanceReportYear.setYearRestBorn(attendanceReport.getYearRestBorn());
			attendanceReportYear.setYearRestBornAttendUsed(attendanceReport.getYearRestBornAttendUsed());
			attendanceReportYear.setYearRestBornRemain(attendanceReport.getYearRestBornRemain());
			attendanceReportYear.setYearRestBornUsed(attendanceReport.getYearRestBornUsed());
			attendanceReportYear.setYearRestCheckUsed(attendanceReport.getYearRestCheckUsed());
			attendanceReportYear.setYearRestDieUsed(attendanceReport.getYearRestDieUsed());
			attendanceReportYear.setYearRestIllUsed(attendanceReport.getYearRestIllUsed());
			attendanceReportYear.setYearRestLastYearAll(attendanceReport.getYearRestLastYearAll());
			attendanceReportYear.setYearRestLastYearUsed(attendanceReport.getYearRestLastYearUsed());
			attendanceReportYear.setYearRestMarryUsed(attendanceReport.getYearRestMarryUsed());
			attendanceReportYear.setYearRestSuckleUsed(attendanceReport.getYearRestSuckleUsed());
			attendanceReportYear.setYearRestThingUsed(attendanceReport.getYearRestThingUsed());
			attendanceReportYear.setYearRestTuneRemain(attendanceReport.getYearRestTuneRemain());
			attendanceReportYear.setYearRestTuneUsed(attendanceReport.getYearRestTuneUsed());
			attendanceReportYear.setYearRestYearAll(attendanceReport.getYearRestYearAll());
			attendanceReportYear.setYearRestYearBegin(attendanceReport.getYearRestYearBegin());
			attendanceReportYear.setYearRestYearUsed(attendanceReport.getYearRestYearUsed());
			attendanceReportYear.setRestYearRemain(attendanceReport.getRestYearRemain());
			
			//取得年初时间和年末时间
			Calendar calendarYear = Calendar.getInstance();
			calendarYear.set(thatYear, 0, 1, 0, 0, 0);
			Date yearBeginDate = calendarYear.getTime();
			calendarYear.set(thatYear, 11, 31);
			Date yearEndDate = calendarYear.getTime();
			
			//更新年累计数据的条件
			AttendanceReportExample arExample = new AttendanceReportExample();
			arExample.createCriteria().andEmployeeIdEqualTo(employeeId)
			.andAttendanceReportDateBetween(yearBeginDate, yearEndDate);
			//更新本年所有日期的年累计字段
			attendanceReportDao.updateByExampleSelective(attendanceReportYear, arExample);
			
		}
	}
	

	@SuppressWarnings("resource")
	@Override
	public String exportAttdanceReport(AttendanceBean attendanceBean,Integer employeeId) {
		SimpleDateFormat sdf = new SimpleDateFormat(" yyyy/MM/dd ");
		
		try {
			long time = System.currentTimeMillis();
			String readUrl = AppConstant.TEMPLATEFILEREPOSITORY + "/考勤记录明细.xlsx";
			String fileurl = AppConstant.REPORTFILEREPOSITORY + "/考勤记录明细" + time + ".xlsx";
			String url = AppConstant.REPORT_RESOURCE + "/考勤记录明细" + time + ".xlsx";
			File file = new File(readUrl);
			if (!file.exists()) {
				try {
					file.createNewFile();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			InputStream inputStream = new FileInputStream(readUrl);
			Workbook wb = null;
			if (readUrl.matches("^.+\\.(?i)(xls)$")) {
				wb = new HSSFWorkbook(inputStream);
			} else if (readUrl.matches("^.+\\.(?i)(xlsx)$")) {
				wb = new XSSFWorkbook(inputStream);
			} else {
				throw new ResultFaultException("8_00001");
			}
			Sheet sheet = wb.getSheetAt(0);

			// 创建单元格样式对象
			XSSFCellStyle ztStyle = (XSSFCellStyle) wb.createCellStyle();

			// 设置字体样式
			Font ztFont = wb.createFont();
			ztFont.setFontHeightInPoints((short) 9); // 将字体大小设置为18px
			ztFont.setFontName("微软雅黑"); // 将“华文行楷”字体应用到当前单元格上
			ztStyle.setFont(ztFont);
			// 设置边框颜色
			ztStyle.setBorderBottom(CellStyle.BORDER_THIN);
			ztStyle.setBorderTop(CellStyle.BORDER_THIN);
			ztStyle.setBorderLeft(CellStyle.BORDER_THIN);
			ztStyle.setBorderRight(CellStyle.BORDER_THIN);

			// 设置单元格边框颜色
			XSSFColor ztColor = new XSSFColor(java.awt.Color.black);
			ztStyle.setBottomBorderColor(ztColor);
			ztStyle.setTopBorderColor(ztColor);
			ztStyle.setLeftBorderColor(ztColor);
			ztStyle.setRightBorderColor(ztColor);
			List<AttendanceBean> attendanceBeanList =new ArrayList<AttendanceBean>();
			// 获取系统当前时间
			List<Integer> employeeIdList = new ArrayList<Integer>();
			if (attendanceBean.getPrivilegeGroupId() == 5) {
				if (attendanceBean.isRoleType()) {
					// 登陆员工ID，查询所属岗位，然后通过岗位查询-岗位下的员工ID
					List<Integer> roleListId = attendanceExtDao.getRolrByEmployeeId(attendanceBean, employeeId);
					if (roleListId.size() > 0) {
						employeeIdList = attendanceExtDao.getEmployeeIdListByRoleId(attendanceBean, employeeId, roleListId);
						if (employeeIdList.size() == 0) {
							 attendanceBeanList =new ArrayList<AttendanceBean>();
						}else{
							attendanceBeanList = attendanceExtDao.getAttendanceList(attendanceBean, employeeIdList, 0, 0,false);
						}
					}
				} else {
					employeeIdList = attendanceExtDao.getEmployeeByCorporation(attendanceBean, employeeId);
					if (employeeIdList.size() == 0) {
						 attendanceBeanList =new ArrayList<AttendanceBean>();
					}else{
						attendanceBeanList = attendanceExtDao.getAttendanceList(attendanceBean, employeeIdList,0, 0,false);
					}
				}
			}
			// 判断是否为分公司HR权限
			else if (attendanceBean.getPrivilegeGroupId() == 4) {
				// 登陆员工ID，查询所属岗位，然后通过岗位查询-岗位下的员工ID
				employeeIdList = attendanceExtDao.getEmployeeByCorporation(attendanceBean, employeeId);
				if (employeeIdList.size() == 0) {
					attendanceBeanList =new ArrayList<AttendanceBean>();
				}else{
					attendanceBeanList = attendanceExtDao.getAttendanceList(attendanceBean, employeeIdList, 0, 0,false);
				}
			}
			// 判断审批人
			else if (attendanceBean.getPrivilegeGroupId() == 3) {
				employeeIdList=new ArrayList<Integer>();
				EmployeeRoleExample employeeRoleExample=new EmployeeRoleExample();
				employeeRoleExample.createCriteria().andEmployeeIdEqualTo(employeeId);
				List<EmployeeRole> employeeRoleList=employeeRoleDao.selectByExample(employeeRoleExample);
				for(int i=0;i<employeeRoleList.size();i++) {
					employeeIdList.addAll(employeeRoleExtDao.selectEmployeeRoleGetEmployeeIdByRoleId(employeeRoleList.get(i).getRoleId()));
				}
				employeeIdList=FactorialUtils.filterEmployeeId(employeeIdList);
				attendanceBeanList = attendanceExtDao.getAttendanceList(attendanceBean, employeeIdList, 0,0, false);
				
				/****原版本-根据岗位ID查询员工ID集合****/
				/*// 登陆员工ID，查询所属岗位，然后通过岗位查询-岗位下的员工ID
				List<Integer> roleListId = attendanceExtDao.getRolrByEmployeeId(attendanceBean, employeeId);
				if (roleListId.size() > 0) {
					employeeList = attendanceExtDao.getEmployeeIdListByRoleId(attendanceBean, employeeId, roleListId);
					if (employeeList.size() == 0) {
						attendanceBeanList =new ArrayList<AttendanceBean>();
					}else{
						attendanceBeanList = attendanceExtDao.getAttendanceList(attendanceBean, employeeList, 0, 0,false);
					}
				}*/
				/************************************/
			}
			// 判断普通用户
			else if (attendanceBean.getPrivilegeGroupId() == 2) {
				attendanceBean.setEmployeeId(employeeId);
				attendanceBeanList = attendanceExtDao.getAttendanceList(attendanceBean, employeeIdList,0, 0,false);
			} else {
				attendanceBeanList = attendanceExtDao.getAttendanceList(attendanceBean, employeeIdList, 0, 0,false);
			}
			//List<AttendanceBean> attendanceBeanList = attendanceExtDao.getAttendanceList(attendanceBean, null, 0, 0,false);
			// 查询补签信息
			List<RetroactiveBean> retroactiveAllList = retroactiveExtDao.getRetroactiveCurrent(
					attendanceBean.getAttendanceDateStart(), attendanceBean.getAttendanceDateEnd());
			for (int i = 0; i < attendanceBeanList.size(); i++) {
				AttendanceBean attendanceReportBean = attendanceBeanList.get(i);
				if (attendanceReportBean == null) {
					continue;
				}

				Row row = sheet.createRow(i + 1);
				Cell cell = row.createCell(0);
				cell.setCellStyle(ztStyle);
				if (attendanceReportBean.getEmployeeNo() != null) {
					cell.setCellValue(attendanceReportBean.getEmployeeNo());
				} else {
					cell.setCellValue("");
				}
				cell = row.createCell(1);
				cell.setCellStyle(ztStyle);
				if (attendanceReportBean.getChineseName() != null) {
					cell.setCellValue(attendanceReportBean.getChineseName());
				} else {
					cell.setCellValue("");
				}
				cell = row.createCell(2);
				cell.setCellStyle(ztStyle);
				if (attendanceReportBean.getEnglishName() != null) {
					cell.setCellValue(attendanceReportBean.getEnglishName());
				} else {
					cell.setCellValue("");
				}
				cell = row.createCell(3);
				cell.setCellStyle(ztStyle);
				if (attendanceReportBean.getAttendanceDate() != null) {
					String attendanceDate = sdf.format(attendanceReportBean.getAttendanceDate());
					cell.setCellValue(attendanceDate);
				} else {
					cell.setCellValue("");
				}
				cell = row.createCell(4);
				cell.setCellStyle(ztStyle);
				if (attendanceReportBean.getOriginalStartTime() != null) {
					cell.setCellValue(attendanceReportBean.getOriginalStartTime());
				} else {
					cell.setCellValue("");
				}
				cell = row.createCell(5);
				cell.setCellStyle(ztStyle);
				for (int j = 0; j < retroactiveAllList.size(); j++) {
					RetroactiveBean retroactiveBean = retroactiveAllList.get(j);
					if (retroactiveBean.getAttendanceId().intValue() == attendanceReportBean.getAttendanceId()
							.intValue() && retroactiveBean.getStartTime() != null) {
						cell.setCellValue(retroactiveBean.getStartTime());
						break;
					} else {
						cell.setCellValue("");
					}

				}

				cell = row.createCell(6);
				cell.setCellStyle(ztStyle);
				if (attendanceReportBean.getOriginalEndTime() != null) {
					cell.setCellValue(attendanceReportBean.getOriginalEndTime());
				} else {
					cell.setCellValue("");
				}
				cell = row.createCell(7);
				cell.setCellStyle(ztStyle);
				for (int j = 0; j < retroactiveAllList.size(); j++) {
					RetroactiveBean retroactiveBean = retroactiveAllList.get(j);
					if (retroactiveBean.getAttendanceId().intValue() == attendanceReportBean.getAttendanceId()
							.intValue() && retroactiveBean.getEndTime() != null) {
						cell.setCellValue(retroactiveBean.getEndTime());
						break;
					} else {
						cell.setCellValue("");

					}
				}
				cell = row.createCell(8);
				cell.setCellStyle(ztStyle);
				if (attendanceReportBean.getAttendanceStateName() != null) {
					cell.setCellValue(attendanceReportBean.getAttendanceStateName());
				} else {
					cell.setCellValue("");
				}
				cell = row.createCell(9);
				cell.setCellStyle(ztStyle);
				if (attendanceReportBean.getIsRepairedName() != null&&attendanceReportBean.getIsRepaired()!=0) {
					cell.setCellValue(attendanceReportBean.getIsRepairedName());
				} else {
					cell.setCellValue("");
				}
				cell = row.createCell(10);
				cell.setCellStyle(ztStyle);
				if (attendanceReportBean.getIsApprovaledName() != null&&attendanceReportBean.getIsApprovaled()!=0) {
					cell.setCellValue(attendanceReportBean.getIsApprovaledName());
				} else {
					cell.setCellValue("");
				}
				cell = row.createCell(11);
				cell.setCellStyle(ztStyle);
				if (attendanceReportBean.getDescription() != null) {
					cell.setCellValue(attendanceReportBean.getDescription());
				} else {
					cell.setCellValue("");
				}

			}

			FileOutputStream outStream = new FileOutputStream(fileurl);
			wb.write(outStream);
			outStream.close();
			return url;
		} catch (Exception e) {

			return null;
		}
	}

	/**
	 * 循环生成一个月的数据
	 */
	@Override
	public void saveAttendanceReportMonth(Date oneDate) {
		//取循环天数
		int days = Integer.parseInt(AppConstant.ATTENDANCE_REPORT_DAYS);
		for (int i = 0; i < days; i++) {
			this.saveAttendanceReport(oneDate, oneDate, null);
			oneDate = DateUtils.addDays(oneDate, -1);
		}
	}

	/**
	 * 每5分钟更新数据
	 */
	@Override
	public void updateAttendanceReportMinutes() {
		//手动执行考勤，造成影响的天s
		List<TaskBean> taskDaysList = taskExtDao.getTaskEmployeeDays();
		//任务表中人--日期，状态0 的数据
		List<TaskBean> employeeDateList = taskExtDao.getTaskEmployeeDate();
		
		//update任务表状态为3 的状态
		if (taskDaysList.size()>0) {
			//update任务表
			attendanceReportExtDao.generateAttendanceApprovalReport();
		}
		//update任务表状态为0 的状态
		if (employeeDateList.size()>0) {
			//update任务表
			attendanceReportExtDao.generateAttendanceApprovalReport();
		}
		
		//循环插入每日--人List对应的数据（先delete）
		if (employeeDateList.size()>0) {
			//Map 日期--人员ids
			Map<Date, List<Integer>> employeeDateMap = new HashMap<>();
			//把日期，人员集合放入Map
			for (TaskBean taskBean : employeeDateList) {
				Date tempDate = taskBean.getTaskDate();
				Integer employeeId = taskBean.getEmployeeId();
				if (employeeDateMap.containsKey(tempDate)) {
					employeeDateMap.get(tempDate).add(employeeId);
				} else {//不包含
					List<Integer> empIdList = new ArrayList<>();
					empIdList.add(employeeId);
					employeeDateMap.put(tempDate, empIdList);
				}
			}
			//循环map
			Set<Date> employeeDateKey = employeeDateMap.keySet();
			Iterator<Date> iter = employeeDateKey.iterator();
			while (iter.hasNext()) {
				Date keyDate = iter.next();
				List<Integer> ids = employeeDateMap.get(keyDate);
				//插入考勤数据表数据
				this.insertData(keyDate, ids);
			}
		}
		//循环执行生成一天数据的存储过程
		if (taskDaysList.size()>0) {
			for (TaskBean taskBean : taskDaysList) {
				Date oneDay = taskBean.getTaskDate();
				//插入考勤数据表数据
				this.insertData(oneDay, null);
			}
		}
	}
	
	/**
	 * 插入考勤数据表数据
	 * @param attendanceReport
	 * @param reportAttendanceBean
	 */
	private void insertData(Date keyDate, List<Integer> ids) {

		//实时查询，获取报表数据
		List<ReportAttendanceBean> raList =	this.getReportList(keyDate, ids);
		//取得年初时间和年末时间
		Calendar calendarYear = Calendar.getInstance();
		calendarYear.setTime(keyDate);
		calendarYear.set(calendarYear.get(Calendar.YEAR), 0, 1, 0, 0, 0);
		Date yearBeginDate = calendarYear.getTime();
		calendarYear.set(calendarYear.get(Calendar.YEAR), 11, 31);
		Date yearEndDate = calendarYear.getTime();
		
		//插入考勤数据表
		for (ReportAttendanceBean reportAttendanceBean : raList) {
			AttendanceReport attendanceReport = new AttendanceReport();
			attendanceReport.setAbsentCount(reportAttendanceBean.getAbsentCount());
			attendanceReport.setAttendanceReportDate(keyDate);
			attendanceReport.setBeAttendanceDays(reportAttendanceBean.getRealAttendanceDays());
			attendanceReport.setChineseName(reportAttendanceBean.getChineseName());
			attendanceReport.setDeptmentNameFour(reportAttendanceBean.getDeptmentNameFour());
			attendanceReport.setDeptmentNameOne(reportAttendanceBean.getDeptmentNameOne());
			attendanceReport.setDeptmentNameThree(reportAttendanceBean.getDeptmentNameThree());
			attendanceReport.setDeptmentNameTwo(reportAttendanceBean.getDeptmentNameTwo());
			attendanceReport.setEmployeeId(reportAttendanceBean.getEmployeeId());
			attendanceReport.setEmployeeNo(reportAttendanceBean.getEmployeeNo());
			attendanceReport.setEmployeeSeparatedDate(reportAttendanceBean.getEmployeeSeparatedDate());
			attendanceReport.setEnglishName(reportAttendanceBean.getEnglishName());
			attendanceReport.setEntryDate(reportAttendanceBean.getEntryDate());
			attendanceReport.setLateCount(reportAttendanceBean.getLateCount());
			attendanceReport.setLeaveEarlyCount(reportAttendanceBean.getLeaveEarlyCount());
			attendanceReport.setLevel(reportAttendanceBean.getLevel());
			attendanceReport.setOvertimeHoliday(reportAttendanceBean.getOvertimeHoliday());
			attendanceReport.setOvertimeNomal(reportAttendanceBean.getOvertimeNomal());
			attendanceReport.setOvertimeWeekend(reportAttendanceBean.getOvertimeWeekend());
			attendanceReport.setRestBornAttendUsed(reportAttendanceBean.getRestBornAttendUsed());
			attendanceReport.setRestBornUsed(reportAttendanceBean.getRestBornUsed());
			attendanceReport.setRestCheckUsed(reportAttendanceBean.getRestCheckUsed());
			attendanceReport.setRestDieUsed(reportAttendanceBean.getRestDieUsed());
			attendanceReport.setRestIllUsed(reportAttendanceBean.getRestIllUsed());
			attendanceReport.setRestMarryUsed(reportAttendanceBean.getRestMarryUsed());
			attendanceReport.setRestSuckleUsed(reportAttendanceBean.getRestSuckleUsed());
			attendanceReport.setRestThingUsed(reportAttendanceBean.getRestThingUsed());
			attendanceReport.setRestTuneUsed(reportAttendanceBean.getRestTuneUsed());
			attendanceReport.setRestYearRemain(reportAttendanceBean.getRestYearRemain());
			attendanceReport.setRestYearUsed(reportAttendanceBean.getRestYearUsed());
			attendanceReport.setRetroactiveCount(reportAttendanceBean.getRetroactiveCount());
			attendanceReport.setRoleName(reportAttendanceBean.getRoleName());
			this.setYearData(attendanceReport, reportAttendanceBean);
			//delete TODO
			AttendanceReportExample arDelExample = new AttendanceReportExample();
			arDelExample.createCriteria().andEmployeeIdEqualTo(reportAttendanceBean.getEmployeeId())
			.andAttendanceReportDateEqualTo(keyDate);
			attendanceReportDao.deleteByExample(arDelExample);
			
			attendanceReportDao.insertSelective(attendanceReport);
			
			//更新年累计数据的条件
			AttendanceReport attendanceReportYear = new AttendanceReport();
			//set年累计字段值
			this.setYearData(attendanceReportYear, reportAttendanceBean);
			AttendanceReportExample arExample = new AttendanceReportExample();
			arExample.createCriteria().andEmployeeIdEqualTo(reportAttendanceBean.getEmployeeId())
			.andAttendanceReportDateBetween(yearBeginDate, yearEndDate);
			//更新本年所有日期的年累计字段
			attendanceReportDao.updateByExampleSelective(attendanceReportYear, arExample);
			
		}
	}
	/**
	 * 实时查询，获取报表数据
	 * @param keyDate
	 * @param ids
	 * @return
	 */
	private List<ReportAttendanceBean> getReportList(Date keyDate, List<Integer> ids) {
		//查询ids对应的employeeNoList
		List<String> employeeNoList = new ArrayList<>();
		if (ids!=null) {
			EmployeeExample empExample = new EmployeeExample();
			empExample.createCriteria().andEmployeeIdIn(ids);
			List<Employee> empList = employeeDao.selectByExample(empExample);
			for (Employee employee : empList) {
				employeeNoList.add(employee.getEmployeeNo());
			}
		}
		Date beginDate=keyDate;
		Date endDate=keyDate;
		//格式化结束日期
		endDate=DateUtils.setHours(endDate, 23);
		endDate=DateUtils.setMinutes(endDate, 59);
		endDate=DateUtils.setSeconds(endDate, 59);
		
		//参数处理
		ReportAttendanceParam paramBean = new ReportAttendanceParam();
		paramBean.setBeginDate(beginDate);
		paramBean.setEndDate(endDate);
		paramBean.setIsPage(0);
		paramBean.setEmployeeList(employeeNoList);
		
		//最终查询结果表
		List<ReportAttendanceBean> reportInfoList = new ArrayList<>();
		
		//取得报表基本信息
		reportInfoList = reportService.getReportAttendanceBaseInfoList(paramBean);
		
		//查询系统配置表
		List<SystemConfigure> systemConfigureList=systemConfigureDao.selectByExample(new SystemConfigureExample());
		
		//生成出员工id列表
		List<Integer> employeeIds = new ArrayList<Integer>();
		for (ReportAttendanceBean reportAttendanceBean : reportInfoList) {
			employeeIds.add(reportAttendanceBean.getEmployeeId());
		}
		//查询的人员id集合为空时，提醒
		/*if (employeeIds.size()==0) {
			throw new ResultFaultException("16_00012");//未查询到信息！
		}*/
		//当年考勤统计
		ReportAttendanceParam paramBeanYear = new ReportAttendanceParam();
		BeanUtils.copyProperties(paramBean, paramBeanYear);
		
		Calendar cdarBegin = Calendar.getInstance();
		cdarBegin.setTime(paramBeanYear.getBeginDate());
		cdarBegin.set(Calendar.MONTH, 0);
		cdarBegin.set(Calendar.DAY_OF_MONTH,1);
		cdarBegin.set(Calendar.HOUR_OF_DAY,0);
		cdarBegin.set(Calendar.MINUTE,0);
		cdarBegin.set(Calendar.SECOND,0);
		cdarBegin.set(Calendar.MILLISECOND,0);
		
		Calendar cdarEnd = Calendar.getInstance();
		cdarEnd.setTime(cdarBegin.getTime());
		cdarEnd.add(Calendar.YEAR, 1);
		cdarEnd.add(Calendar.MILLISECOND, -1);
		
		paramBean.setLastBeginDate(cdarBegin.getTime());
		paramBean.setLastEndDate(cdarEnd.getTime());
		
		//查询时间的开始，结束时间
		Calendar yearCalendarEnd = Calendar.getInstance();
		yearCalendarEnd.setTime(beginDate);
		yearCalendarEnd.set(Calendar.MONTH, 0);
		yearCalendarEnd.set(Calendar.DAY_OF_MONTH,1);
		yearCalendarEnd.set(Calendar.HOUR_OF_DAY,0);
		yearCalendarEnd.set(Calendar.MINUTE,0);
		yearCalendarEnd.set(Calendar.SECOND,0);
		yearCalendarEnd.set(Calendar.MILLISECOND,0);
		Date yearBeginDate=yearCalendarEnd.getTime();
		paramBean.setYearBeginDate(yearBeginDate);
		
		Date endDateAddOne=DateUtils.addDays(endDate, 1);
		paramBean.setEndDateAddOne(endDateAddOne);
		
		//查询报表
		List<ReportAttendanceBean> reportList=reportExtDao.selectReportList(paramBean, employeeIds);
		
		//查询人员
		EmployeeExample employeeExample=new EmployeeExample();
		employeeExample.createCriteria().andEmployeeIdIn(employeeIds);
		List<Employee> employeeList=employeeDao.selectByExample(employeeExample);
		Map<Integer, Employee> employeeMap = new HashMap<Integer, Employee>();
		for(int ei=0;ei<employeeList.size();ei++){
			employeeMap.put(employeeList.get(ei).getEmployeeId(), employeeList.get(ei));
		}
		
		//年假查询参数
		RestVacationBean restVacationBean=new RestVacationBean();
		restVacationBean.setFurloughType(1);
		restVacationBean.setStartDate(paramBean.getBeginDate());
		
		//取年份
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(restVacationBean.getStartDate());
		int thatYear = calendar.get(Calendar.YEAR);
		int lastYear = thatYear - 1;
		
		//年假
		FurloughBalanceExample furloughBalanceExample=new FurloughBalanceExample();
		furloughBalanceExample.createCriteria()
		.andEmployeeIdIn(employeeIds)
		.andFurloughBalanceTypeEqualTo(1)
		.andYearEqualTo(Integer.toString(thatYear));
		
		List<FurloughBalance> fList=furloughBalanceDao.selectByExample(furloughBalanceExample);
		
		//去年
		FurloughBalanceExample furloughBalanceExample2=new FurloughBalanceExample();
		furloughBalanceExample2.createCriteria()
		.andEmployeeIdIn(employeeIds)
		.andFurloughBalanceTypeEqualTo(1)
		.andYearEqualTo(Integer.toString(lastYear));
		
		List<FurloughBalance> lastFList=furloughBalanceDao.selectByExample(furloughBalanceExample2);
		
		//查询当天年假申请
		RequestExample requestExample=new RequestExample();
		requestExample.createCriteria()
		.andEmployeeIdIn(employeeIds)
		.andRequestTypeEqualTo(1)
		.andReportYearEqualTo(thatYear)
		.andApprovalStateEqualTo(1);
		
		List<Request> rList=requestDao.selectByExample(requestExample);
		
		Map<Integer, List<Request>> thatYearRequestMap = new HashMap<Integer, List<Request>>();
		for(int ri=0;ri<rList.size();ri++){
			if (thatYearRequestMap.containsKey(rList.get(ri).getEmployeeId())) {
				List<Request> eList = thatYearRequestMap.get(rList.get(ri).getEmployeeId());
				eList.add(rList.get(ri));
				thatYearRequestMap.put(rList.get(ri).getEmployeeId(), eList);
			} else {
				List<Request> eList = new ArrayList<Request>();
				eList.add(rList.get(ri));
				thatYearRequestMap.put(rList.get(ri).getEmployeeId(), eList);
			}
		}
		
		//在申请中的去年年假时长
		RequestExample requestExample2=new RequestExample();
		requestExample2.createCriteria()
		.andEmployeeIdIn(employeeIds)
		.andRequestTypeEqualTo(1)
		.andReportYearEqualTo(lastYear)
		.andApprovalStateEqualTo(1);
		
		List<Request> rLastList=requestDao.selectByExample(requestExample2);
		
		Map<Integer, List<Request>> lastYearRequestMap = new HashMap<Integer, List<Request>>();
		for(int lyi=0;lyi<rLastList.size();lyi++){
			if (lastYearRequestMap.containsKey(rLastList.get(lyi).getEmployeeId())) {
				List<Request> eList = lastYearRequestMap.get(rLastList.get(lyi).getEmployeeId());
				eList.add(rLastList.get(lyi));
				lastYearRequestMap.put(rLastList.get(lyi).getEmployeeId(), eList);
			} else {
				List<Request> eList = new ArrayList<Request>();
				eList.add(rLastList.get(lyi));
				lastYearRequestMap.put(rLastList.get(lyi).getEmployeeId(), eList);
			}
		}
		
		//把统计信息放入报表对象中
		for (int i=0;i<reportInfoList.size();i++) {
			ReportAttendanceBean reportAttendanceBean = reportInfoList.get(i);
			Integer employeeId=reportAttendanceBean.getEmployeeId();
			for(int j=0;j<reportList.size();j++) {
				ReportAttendanceBean rab=reportList.get(j);
				if(rab.getMapEmployeeId().equals(employeeId)) {
					//员工应出勤天数(应出勤天数=当月排班+法定假-产假（按排班休的产假）)
					if (rab.getRestBornUsed()!= null || rab.getRestBornAttendUsed()!=null) {
						int restBornUsed = 0;//产假天数
						int restBornAttendUsed = 0;//陪护假天数
						if (rab.getRestBornUsed()!= null) {
							restBornUsed = rab.getRestBornUsed();
						}
						if (rab.getRestBornAttendUsed()!=null) {
							restBornAttendUsed = rab.getRestBornAttendUsed();
						}
						reportInfoList.get(i).setRealAttendanceDays(rab.getRealAttendanceDays()
								-restBornUsed-restBornAttendUsed);
					} else {
						reportInfoList.get(i).setRealAttendanceDays(rab.getRealAttendanceDays());
					}
					//员工迟到次数
					reportInfoList.get(i).setLateCount(rab.getLateCount());
					//员工早退次数
					reportInfoList.get(i).setLeaveEarlyCount(rab.getLeaveEarlyCount());
					//员工旷工次数
					reportInfoList.get(i).setAbsentCount(rab.getAbsentCount());
					//员工补签次数
					reportInfoList.get(i).setRetroactiveCount(rab.getRetroactiveCount());
					//员工平日加班天数
//					Float value = (float)(Math.round((rab.getOvertimeNomal()/60/8)*100))/100;
					reportInfoList.get(i).setOvertimeNomal(this.minsToDays(rab.getOvertimeNomal()));
					//员工双休日加班天数
					reportInfoList.get(i).setOvertimeWeekend(this.minsToDays(rab.getOvertimeWeekend()));
					//员工节假日加班天数
					reportInfoList.get(i).setOvertimeHoliday(this.minsToDays(rab.getOvertimeHoliday()));
					//员工请年假天数
					reportInfoList.get(i).setRestYearUsed(this.minsToDays(rab.getRestYearUsed()));
					//员工请假调休天数
					reportInfoList.get(i).setRestTuneUsed(this.minsToDays(rab.getRestTuneUsed()));
					//员工请产假天数(按筛选日期统计)
					reportInfoList.get(i).setRestBornUsed(rab.getRestBornUsed());
					//员工请产检假天数
					reportInfoList.get(i).setRestCheckUsed(this.minsToDays(rab.getRestCheckUsed()));
					//员工请丧假天数
					reportInfoList.get(i).setRestDieUsed(rab.getRestDieUsed());
					//员工请婚假天数
					reportInfoList.get(i).setRestMarryUsed(rab.getRestMarryUsed());
					//员工请陪产假天数
					reportInfoList.get(i).setRestBornAttendUsed(rab.getRestBornAttendUsed());
					//员工请哺乳假天数
					reportInfoList.get(i).setRestSuckleUsed(this.minsToDays(rab.getRestSuckleUsed()));
					//员工请病假天数
					reportInfoList.get(i).setRestIllUsed(this.minsToDays(rab.getRestIllUsed()));
					//员工请事假天数
					reportInfoList.get(i).setRestThingUsed(this.minsToDays(rab.getRestThingUsed()));
					//当年考勤统计
					//员工迟到次数累计
					reportInfoList.get(i).setYearLateCount(rab.getYearLateCount());
					//员工早退次数
					reportInfoList.get(i).setYearLeaveEarlyCount(rab.getYearLeaveEarlyCount());
					//员工旷工次数
					reportInfoList.get(i).setYearAbsentCount(rab.getYearAbsentCount());
					//员工平日加班天数
					reportInfoList.get(i).setYearOvertimeNomal(this.minsToDays(rab.getYearOvertimeNomal()));
					//员工双休日加班天数
					reportInfoList.get(i).setYearOvertimeWeekend(this.minsToDays(rab.getYearOvertimeWeekend()));
					//员工节假日加班天数
					reportInfoList.get(i).setYearOvertimeHoliday(this.minsToDays(rab.getYearOvertimeHoliday()));
					//年假开始日期
					reportInfoList.get(i).setYearRestYearBegin(rab.getYearRestYearBegin());
					
					//年假
					RestVacationBean newRestVacationBean = reportResultService.getLastYearYearFurlough(restVacationBean, employeeId,systemConfigureList,employeeMap,fList,lastFList,thatYearRequestMap,lastYearRequestMap);
					
					//可享受年假
					reportInfoList.get(i).setYearRestYearAll(newRestVacationBean.getTotalVacation().divide(new BigDecimal(60*8), 0, BigDecimal.ROUND_DOWN).floatValue());
					//员工请年假天数
					reportInfoList.get(i).setYearRestYearUsed((newRestVacationBean.getTotalVacation().subtract(newRestVacationBean.getRealRestVacation())).divide(new BigDecimal(60*8), 2, BigDecimal.ROUND_HALF_UP).floatValue());
					//剩余年假
					reportInfoList.get(i).setRestYearRemain(newRestVacationBean.getRealRestVacation().divide(new BigDecimal(60*8), 2, BigDecimal.ROUND_HALF_UP).floatValue());
					//去年可享受年假天数
					reportInfoList.get(i).setYearRestLastYearAll(newRestVacationBean.getLastYearTotalVacation().divide(new BigDecimal(60*8), 0, BigDecimal.ROUND_DOWN).floatValue());
					//员工请去年年假天数
					reportInfoList.get(i).setYearRestLastYearUsed((newRestVacationBean.getLastYearTotalVacation().subtract(newRestVacationBean.getRealLastYearRestVacation())).divide(new BigDecimal(60*8), 0, BigDecimal.ROUND_DOWN).floatValue());
					//员工请假调休天数
					reportInfoList.get(i).setYearRestTuneUsed(this.minsToDays(rab.getYearRestTuneUsed()));
					//剩余调休假
					reportInfoList.get(i).setYearRestTuneRemain(this.minsToDays(rab.getYearRestTuneRemain()));
					//员工请病假天数
					reportInfoList.get(i).setYearRestIllUsed(this.minsToDays(rab.getYearRestIllUsed()));
					//员工请事假天数
					reportInfoList.get(i).setYearRestThingUsed(this.minsToDays(rab.getYearRestThingUsed()));
					//员工请产检假天数
					reportInfoList.get(i).setYearRestCheckUsed(this.minsToDays(rab.getYearRestCheckUsed()));
					//可休产假(年)
					reportInfoList.get(i).setYearRestBorn(rab.getYearRestBorn());
					//员工已休产假天数(年)
					reportInfoList.get(i).setYearRestBornUsed(rab.getYearRestBornUsed());
					//剩余产假(年)
					reportInfoList.get(i).setYearRestBornRemain(rab.getYearRestBornRemain());
					//员工请哺乳假天数
					reportInfoList.get(i).setYearRestSuckleUsed(this.minsToDays(rab.getYearRestSuckleUsed()));
					//员工请婚假天数
					reportInfoList.get(i).setYearRestMarryUsed(rab.getYearRestMarryUsed());
					//员工请丧假天数
					reportInfoList.get(i).setYearRestDieUsed(rab.getYearRestDieUsed());
					//员工请陪产假天数
					reportInfoList.get(i).setYearRestBornAttendUsed(rab.getYearRestBornAttendUsed());				
				}
			}
		}
		return reportInfoList;
	}

	/**
	 * 更新年累计字段值
	 * @param attendanceReportYear
	 * @param reportAttendanceBean
	 */
	private void setYearData(AttendanceReport attendanceReportYear, ReportAttendanceBean reportAttendanceBean) {
		attendanceReportYear.setEmployeeNo(reportAttendanceBean.getEmployeeNo());//处理update为null的情况
		attendanceReportYear.setYearAbsentCount(reportAttendanceBean.getYearAbsentCount());
		attendanceReportYear.setYearLateCount(reportAttendanceBean.getYearLateCount());
		attendanceReportYear.setYearLeaveEarlyCount(reportAttendanceBean.getYearLeaveEarlyCount());
		attendanceReportYear.setYearOvertimeHoliday(reportAttendanceBean.getYearOvertimeHoliday());
		attendanceReportYear.setYearOvertimeNomal(reportAttendanceBean.getYearOvertimeNomal());
		attendanceReportYear.setYearOvertimeWeekend(reportAttendanceBean.getYearOvertimeWeekend());
		attendanceReportYear.setYearRestBorn(reportAttendanceBean.getYearRestBorn());
		attendanceReportYear.setYearRestBornAttendUsed(reportAttendanceBean.getYearRestBornAttendUsed());
		attendanceReportYear.setYearRestBornRemain(reportAttendanceBean.getYearRestBornRemain());
		attendanceReportYear.setYearRestBornUsed(reportAttendanceBean.getYearRestBornUsed());
		attendanceReportYear.setYearRestCheckUsed(reportAttendanceBean.getYearRestCheckUsed());
		attendanceReportYear.setYearRestDieUsed(reportAttendanceBean.getYearRestDieUsed());
		attendanceReportYear.setYearRestIllUsed(reportAttendanceBean.getYearRestIllUsed());
		attendanceReportYear.setYearRestLastYearAll(reportAttendanceBean.getYearRestLastYearAll());
		attendanceReportYear.setYearRestLastYearUsed(reportAttendanceBean.getYearRestLastYearUsed());
		attendanceReportYear.setYearRestMarryUsed(reportAttendanceBean.getYearRestMarryUsed());
		attendanceReportYear.setYearRestSuckleUsed(reportAttendanceBean.getYearRestSuckleUsed());
		attendanceReportYear.setYearRestThingUsed(reportAttendanceBean.getYearRestThingUsed());
		attendanceReportYear.setYearRestTuneRemain(reportAttendanceBean.getYearRestTuneRemain());
		attendanceReportYear.setYearRestTuneUsed(reportAttendanceBean.getYearRestTuneUsed());
		attendanceReportYear.setYearRestYearAll(reportAttendanceBean.getYearRestYearAll());
		attendanceReportYear.setYearRestYearBegin(reportAttendanceBean.getYearRestYearBegin());
		attendanceReportYear.setYearRestYearUsed(reportAttendanceBean.getYearRestYearUsed());
		attendanceReportYear.setRestYearRemain(reportAttendanceBean.getRestYearRemain());
	}
	/**
	 * 分钟数转换成day，保留两位小数（除以60*8）
	 * @param mins
	 * @return 天数
	 */
	private Float minsToDays(Float mins) {
		if (mins!=null) {
			return (float)(Math.round((mins/60/8)*100))/100;
		} else {
			return null;
		}
	}
	
}
